//
//  BasicTableViewController.swift
//  weibo
//
//  Created by cmh on 15/8/31.
//  Copyright © 2015年 cmh. All rights reserved.
//

import UIKit

class BasicTableViewController: UITableViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
    }
    // 记录用户是否是登陆状态
    var logon = UserAccountViewModel.shareUserAccount.userLogon
    
    // 将登陆视图设置为一个属性，别的类可以访问
    var logonView: LogonView?
    
    // 加载view的时候做判断
    override func loadView() {
        
        logon ? super.loadView() : setLogonView()
        
    }

    // 加载如果没有登陆时的view视图
     private func setLogonView() {
        logonView = LogonView()
        view = logonView
        
        // 设置注册和登陆
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "showRegister")
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "showLogon")
        
        // 登陆和注册按钮的监听
        logonView?.logonButton.addTarget(self, action: "showLogon", forControlEvents: UIControlEvents.TouchUpInside)
        
        logonView?.registerButton.addTarget(self, action: "showRegister", forControlEvents: UIControlEvents.TouchUpInside)
    }
    
    // 登陆
    @objc private func showLogon() {
        let vc = UINavigationController(rootViewController: OAuthViewController())
        
        presentViewController(vc, animated: true, completion: nil)
        
    }

    // 注册
    @objc private func showRegister() {
    
        printLog("注册")
    }
    
}
